<?php
// 借款(借出,相对于客户来说)
class LoanAction extends Action {
    
    //贷款列表
    public function index(){

        $name = $this->getActionName();
        $m = M($name);
        import('ORG.Util.Page');// 导入分页类

        $map=array('status'=>1);

        $count = $m->where($map)->count();// 查询满足要求的总记录数
        $Page = new Page($count,2);// 实例化分页类 传入总记录数
        $Page->rollPage = 5;	//最多显示20个分页

        // 进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用 $_GET[p]获取
        $nowPage = $this->_get('p') ? intval($this->_get('p')) : 1;

        $list = $m->where($map)->order('create_time desc')->page($nowPage.','.$Page->listRows)->select();
        //ECHO $m->getLastSql();
        $Page->setConfig('theme','%upPage% %downPage% %prePage% %linkPage% %nextPage%');
        $page = $Page->show();// 分页显示输出

        $this->assign ('page', $page );   
	$this->assign('list',$list);
	$this->display();
    }

    //显示详细信息
    public function detail()
    {
        if(isset($_GET['aid'])){
            $aid = intval($_GET['aid']);
            $_SESSION['aid'] = $aid;
        }else{
            if(isset($_SESSION['aid'])) $aid = $_SESSION['aid'];
            else $aid=0;
        }

        $id = $this->_get('id');
        $m = M('Info');
        $new = $m->find($id);
        // $new['content'] = htmlspecialchars($new['content']);
        $this->assign('aid',$aid);
        $this->assign('new',$new);// 赋值数据集
        $this->display();
    }

    //显示发布信息
    public function add()
    {
        if(isset($_GET['aid'])){
                $aid = intval($_GET['aid']);
                $_SESSION['aid'] = $aid;
        }else{
                if(isset($_SESSION['aid'])) $aid = $_SESSION['aid'];
                else $aid=0;
        }

        //信息分类
        $this->assign('type', $type);
        $this->assign('aid', $aid);
        $this->display('add');
    }

    //发布信息
    public function write()
    {
        $data = array();
        if($_POST['title']){
            $m=M('Info');
            $m->create();
            $m->create_time = date('Y-m-d H:i:s');
            if(!empty($_SESSION['aid']))$aid = $_SESSION['aid'];
            else $aid = intval($_REQUEST['aid']);
            $m->aid = $aid;
            $result = $m->add();

            if($result) {
                $data['ok']=1;
            }else{
                $data['ok']=0;
            }
        }else{
            $data['ok']=0;
        }

        echo json_encode($data);
    }

}

